package com.atguigu;

import java.io.File;
import java.io.IOException;

/**
 * @program: IDEAcode
 * @description:
 * @author: Mr.zjx
 * create: 2021-08-13-19-53
 **/
public class Test {
    public static void main(String[] args) throws Exception {
        fileConstructor1();
        fileConstructor2();
        creatFile();
        creatDir();
        testdelete();
        isDirectoryFile();
    }
    private static void fileConstructor1(){
        File file = new File("C:\\Program Files\\Java\\jdk1.8.0_221\\bin\\javac.exe");
        System.out.println("file = " + file);
        String name = file.getName();
        System.out.println("name = " + name);
        String path = file.getPath();
        System.out.println("path = " + path);
        File parentFile = file.getParentFile().getParentFile().getParentFile().getParentFile();
        System.out.println("parentFile = " + parentFile);
    }

    private static void fileConstructor2(){
        File file = new File("C:\\Java","jdk1.8.0_221");
        System.out.println("file = " + file);
    }

    private static void creatFile() throws Exception {
        File file = new File("G:\\尚硅谷学习\\学习视频\\Java及数据库\\day19\\笔记\\1.txt");
        boolean newFile = file.createNewFile();
        System.out.println("newFile = " + newFile);
    }

    private static void creatDir(){
        File file = new File("G:\\尚硅谷学习\\学习视频\\Java及数据库\\day19\\笔记\\mytxt");
        boolean mkdir = file.mkdir();
        System.out.println("mkdir = " + mkdir);
    }

    private static void testdelete(){
        File file = new File("G:\\尚硅谷学习\\学习视频\\Java及数据库\\day19\\笔记\\1.txt");
        boolean delete = file.delete();
        System.out.println("delete = " + delete);
    }

    private static void isDirectoryFile(){
        File file = new File("G:\\尚硅谷学习\\学习视频\\Java及数据库\\day19\\笔记\\mytxt");
        if (file.exists()){
            boolean directory = file.isDirectory();
            System.out.println("directory = " + directory);
        }
    }
}
